#include "../include/unicebot_gui/KinectWidget.hpp"
#include <QApplication>
#include <QPainter>

namespace unicebot_gui {

KinectWidget::KinectWidget(QWidget *parent) :
		QWidget(parent) {
	ROS_WARN("KinectWidget::KinectWidget");

}

KinectWidget::~KinectWidget() {

}

void KinectWidget::paintEvent(QPaintEvent *event) {
	paintImage(event);
	//paintLine(event);
	paintKinect(event);

}

void KinectWidget::paintKinect(QPaintEvent *event) {
	ROS_WARN("KinectWidget::paintKinect");

	if(!imageToDraw.isNull()){
		mutex.lock();
		QPainter widgetPainter(this);
		widgetPainter.drawImage(rect(), imageToDraw, imageToDraw.rect());
		mutex.unlock();

	}
} //paintKinect

void KinectWidget::paintImage(QPaintEvent *event) {
	ROS_WARN("KinectWidget::paintImage");

	IplImage *img = cvLoadImage("resources/images/test.jpg", CV_LOAD_IMAGE_COLOR);
	QImage image((uchar *) img->imageData, img->width, img->height,
			img->widthStep, QImage::Format_RGB888);
	image = image.rgbSwapped();
	QPainter widgetPainter(this);
	widgetPainter.drawImage(rect(), image, image.rect());

} //paintImage

void KinectWidget::paintLine(QPaintEvent *event) {
	ROS_WARN("KinectWidget::paintLine");
	QPen pen(Qt::black, 2, Qt::SolidLine);

	QPainter painter(this);

	painter.setPen(pen);
	painter.drawLine(20, 40, 250, 40);

	pen.setStyle(Qt::DashLine);
	painter.setPen(pen);
	painter.drawLine(20, 80, 250, 80);

	pen.setStyle(Qt::DashDotLine);
	painter.setPen(pen);
	painter.drawLine(20, 120, 250, 120);

	pen.setStyle(Qt::DotLine);
	painter.setPen(pen);
	painter.drawLine(20, 160, 250, 160);

	pen.setStyle(Qt::DashDotDotLine);
	painter.setPen(pen);
	painter.drawLine(20, 200, 250, 200);

	QVector<qreal> dashes;
	qreal space = 4;

	dashes << 1 << space << 5 << space;

	pen.setStyle(Qt::CustomDashLine);
	pen.setDashPattern(dashes);
	painter.setPen(pen);
	painter.drawLine(20, 240, 250, 240);

} //paintLines

} //namespace unicebot_gui {
